/**
 * Huisou.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */

package com.chenzehe.hadoop.test;

import java.io.IOException;
import java.net.URI;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IOUtils;

/**
 * @description
 * 
 * @author chenzehe
 * @email hljuczh@163.com
 * @create 2013-8-9 上午11:46:30
 */

public class FileSystemSeek {
	public static void main(String[] args) {
		Configuration conf = new Configuration();
		String path = "hdfs://192.168.0.2:49000/user/hadoop/example.txt";
		FileSystem fs = null;
		FSDataInputStream in = null;
		try {
			fs = FileSystem.get(URI.create(path), conf);
			in = fs.open(new Path(path));
			IOUtils.copyBytes(in, System.out, 4096, false);
			in.seek(3);
			IOUtils.copyBytes(in, System.out, 4096, false);
		}
		catch (IOException e) {
			e.printStackTrace();
		}
		finally {
			IOUtils.closeStream(in);
		}
	}
}
